package com.hongmeng.web.controller.operater.aliyun;

import com.hongmeng.common.core.domain.AjaxResult;
import com.hongmeng.operater.service.aliyun.IVodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * 阿里云视频管理
 */
@Api("阿里云视频管理")
@RestController
@RequestMapping("/aliyun/video")
@Slf4j
public class AliyunController {

    @Autowired
    private IVodService vodService;

    /**
     * 创建阿里云上传凭证
     * @param fileName        文件名
     * @param videoTitle      视频标题
     * @param templateGroupId templateGroupId
     * @param cateId          cateId
     * @return AjaxResult
     */
    @ApiOperation("创建阿里云上传凭证")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fileName",value = "文件名",dataType = "String",required = true,paramType = "query"),
            @ApiImplicitParam(name = "videoTitle",value = "视频标题",dataType = "String",required = true,paramType = "query"),
            @ApiImplicitParam(name = "templateGroupId",value = "templateGroupId",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "cateId",value = "cateId",dataType = "Long",paramType = "query")
    })
    @PostMapping("/getVoidUploadToken")
    public AjaxResult getVoidUploadToken(@NotNull String fileName, @NotNull String videoTitle, String templateGroupId, Long cateId){
        log.info("创建阿里云上传凭证，文件名为:{},视频标题为:{}",fileName,videoTitle);
        return vodService.getVoidUploadToken(fileName,videoTitle,templateGroupId,cateId);
    }

    /**
     * 重新获取凭证
     * @param videoId  videoId
     * @return AjaxResult
     */
    @ApiOperation("重新获取凭证")
    @ApiImplicitParam(name = "videoId",value = "videoId",dataType = "String",required = true,paramType = "query")
    @PostMapping("/refreshUploadVideo")
    public AjaxResult refreshUploadVideo(@NotNull String videoId){
        log.info("重新获取上传凭证，视频id为:{}",videoId);
        return vodService.refreshUploadVideo(videoId);
    }

    /**
     * 获取视频播放地址
     * @param videoId 视频id(凭证)
     * @return AjaxResult
     */
    @ApiOperation("获取视频播放地址")
    @ApiImplicitParam(name = "videoId",value = "视频id(凭证)",required = true,paramType = "query")
    @GetMapping("/getPlayUrl")
    public AjaxResult getPlayUrl(String videoId){
        log.info("通过视频id获取视频播放地址，视频id为:{}",videoId);
        vodService.getVodOriginalFileById(videoId);
        return vodService.getPlayUserByVideoId(videoId);
    }
}
